<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!--  百度cdn引入jquery  -->
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<form id="registform" method="post" enctype="multipart/form-data">
    <input type="file" name="file"/>

    <input type="text" name="username"/>
</form>
<button id="btn1">提交</button>
<script>
    //给页面的按钮注册单击事件
    $(function () {
        $("#btn1").click(function () {
            //获取表单内容
           var formData =  new FormData(document.getElementById("registform"));
            // 发送ajax请求
            $.ajax({
                url: "/up/test1",
                type: "post",
                data: formData,
                // 使用ajax请求去上传文件需要把如下两个属性设置为false，固定写法
                processData: false,
                contentType: false,
                success: function (result) {
                    console.log(result);
                },
                error: function (result) {
                    console.log(result);
                }
            });
        });
    });
</script>
</body>
</html>